Hands on Exercise 3: 1st Order Spatial Point Patterns Analysis Methods
1. Installing and Loading the R packages
In this hands-on exercise, five R packages will be used, they are:
sf, a relatively new R package specially designed to import, manage and process vector-based geospatial data in R.
spatstat, which has a wide range of useful functions for point pattern analysis. In this hands-on exercise, it will be used to perform 1st- and 2nd-order spatial point patterns analysis and derive kernel density estimation (KDE) layer.
raster which reads, writes, manipulates, analyses and model of gridded spatial data (i.e. raster). In this hands-on exercise, it will be used to convert image output generate by spatstat into raster format.
maptools which provides a set of tools for manipulating geographic data. In this hands-on exercise, we mainly use it to convert Spatial objects into ppp format of spatstat.
tmap which provides functions for plotting cartographic quality static point patterns maps or interactive maps by using leaflet API.
Use the code chunk below to install and launch the five R packages.
Installing package into 'C:/Users/felie/AppData/Local/R/win-library/4.3'
(as 'lib' is unspecified)
package 'maptools' successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\felie\AppData\Local\Temp\RtmpAPtXCf\downloaded_packages
ppp is a point pattern object (of spatstat package)
Difference between Spatial Data Types (Vector and Raster):
Raster data works with pixels
Vector data consists of coordinates
we can convert vector to raster, vice versa
2. Spatial Data Wrangling
2.1 Importing the spatial data
In this section, st_read() of sf package will be used to import these three geospatial data sets into R.
Own notes:
Spatial vs Geospatial: geospatial is of or pertaining to a geographic location, especially data while spatial is of or pertaining to space
st_transform: takes a geometry (childcare_sf) and a spatial reference system identifier (3414) as input parameters and transforms the geometry to be represented in the given spatial reference system
Notice that all the geospatial layers are within the same map extend. This shows that their referencing system and coordinate values are referred to similar spatial context. This is very important in any geospatial analysis.
Alternatively, we can also prepare a pin map by using the code chunk below.
tmap_mode('view')
tmap mode set to interactive viewing
tm_shape(childcare_sf)+tm_dots()
tmap_mode('plot')
tmap mode set to plotting
Notice that at the interactive mode, tmap is using leaflet for R API. The advantage of this interactive pin map is it allows us to navigate and zoom around the map freely. We can also query the information of each simple feature (i.e. the point) by clicking of them. Last but not least, you can also change the background of the internet map layer. Currently, three internet map layers are provided. They are: ESRI.WorldGrayCanvas, OpenStreetMap, and ESRI.WorldTopoMap. The default is ESRI.WorldGrayCanvas.
Reminder: Always remember to switch back to plot mode after the interactive map. This is because, each interactive mode will consume a connection. You should also avoid displaying ecessive numbers of interactive maps (i.e. not more than 10) in one RMarkdown document when publish on Netlify.
3. Data Wrangling
Although simple feature data frame is gaining popularity again sp’s Spatial* classes, there are, however, many geospatial analysis packages require the input geospatial data in sp’s Spatial* classes. In this section, you will learn how to convert simple feature data frame to sp’s Spatial* class.
3.1 Converting sf data frames to sp’s Spatial* class
The code below uses as_Spatial() of sf package to convert the three geospatial data from simple feature data frame to sp’s Spatial* class.
Simple feature collection with 6 features and 15 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 24468.89 ymin: 28369.47 xmax: 32362.39 ymax: 30542.74
Projected CRS: SVY21 / Singapore TM
OBJECTID SUBZONE_NO SUBZONE_N SUBZONE_C CA_IND PLN_AREA_N
1 1 1 MARINA SOUTH MSSZ01 Y MARINA SOUTH
2 2 1 PEARL'S HILL OTSZ01 Y OUTRAM
3 3 3 BOAT QUAY SRSZ03 Y SINGAPORE RIVER
4 4 8 HENDERSON HILL BMSZ08 N BUKIT MERAH
5 5 3 REDHILL BMSZ03 N BUKIT MERAH
6 6 7 ALEXANDRA HILL BMSZ07 N BUKIT MERAH
PLN_AREA_C REGION_N REGION_C INC_CRC FMEL_UPD_D X_ADDR
1 MS CENTRAL REGION CR 5ED7EB253F99252E 2014-12-05 31595.84
2 OT CENTRAL REGION CR 8C7149B9EB32EEFC 2014-12-05 28679.06
3 SR CENTRAL REGION CR C35FEFF02B13E0E5 2014-12-05 29654.96
4 BM CENTRAL REGION CR 3775D82C5DDBEFBD 2014-12-05 26782.83
5 BM CENTRAL REGION CR 85D9ABEF0A40678F 2014-12-05 26201.96
6 BM CENTRAL REGION CR 9D286521EF5E3B59 2014-12-05 25358.82
Y_ADDR SHAPE_Leng SHAPE_Area geometry
1 29220.19 5267.381 1630379.3 MULTIPOLYGON (((31495.56 30...
2 29782.05 3506.107 559816.2 MULTIPOLYGON (((29092.28 30...
3 29974.66 1740.926 160807.5 MULTIPOLYGON (((29932.33 29...
4 29933.77 3313.625 595428.9 MULTIPOLYGON (((27131.28 30...
5 30005.70 2825.594 387429.4 MULTIPOLYGON (((26451.03 30...
6 29991.38 4428.913 1030378.8 MULTIPOLYGON (((25899.7 297...
head(mpsz)
OBJECTID SUBZONE_NO SUBZONE_N SUBZONE_C CA_IND PLN_AREA_N
1 1 1 MARINA SOUTH MSSZ01 Y MARINA SOUTH
2 2 1 PEARL'S HILL OTSZ01 Y OUTRAM
3 3 3 BOAT QUAY SRSZ03 Y SINGAPORE RIVER
4 4 8 HENDERSON HILL BMSZ08 N BUKIT MERAH
5 5 3 REDHILL BMSZ03 N BUKIT MERAH
6 6 7 ALEXANDRA HILL BMSZ07 N BUKIT MERAH
PLN_AREA_C REGION_N REGION_C INC_CRC FMEL_UPD_D X_ADDR
1 MS CENTRAL REGION CR 5ED7EB253F99252E 2014-12-05 31595.84
2 OT CENTRAL REGION CR 8C7149B9EB32EEFC 2014-12-05 28679.06
3 SR CENTRAL REGION CR C35FEFF02B13E0E5 2014-12-05 29654.96
4 BM CENTRAL REGION CR 3775D82C5DDBEFBD 2014-12-05 26782.83
5 BM CENTRAL REGION CR 85D9ABEF0A40678F 2014-12-05 26201.96
6 BM CENTRAL REGION CR 9D286521EF5E3B59 2014-12-05 25358.82
Y_ADDR SHAPE_Leng SHAPE_Area
1 29220.19 5267.381 1630379.3
2 29782.05 3506.107 559816.2
3 29974.66 1740.926 160807.5
4 29933.77 3313.625 595428.9
5 30005.70 2825.594 387429.4
6 29991.38 4428.913 1030378.8
plot(mpsz_sf)
Warning: plotting the first 9 out of 15 attributes; use max.plot = 15 to plot
all
plot(mpsz)
head(sg)
GDO_GID MSLINK MAPID COSTAL_NAM
1 1 1 0 Linkway
2 2 3 0 SENTOSA
3 3 5 0 PULAU SARIMBUN
4 4 6 0 PULAU SAMULUN
5 5 7 0 SINGAPORE - MAIN ISLAND
6 6 8 0 PULAU KEPPEL
plot(sg_sf)
plot(sg)
3.2 Converting the Spatial* class into generic sp format
spatstat requires the analytical data in ppp object form. There is no direct way to convert a Spatial* classes into ppp object. We need to convert the Spatial classes* into Spatial object first.
This code below will be converting Spatial* classes into generic sp objects
Planar point pattern: 1925 points
window: rectangle = [11810.03, 45404.24] x [25596.33, 49300.88] units
Let’s examine the difference by plotting chidlcare_ppp
plot(childcare_ppp)
We now look at the summary statistics of the newly created ppp object.
summary(childcare_ppp)
Planar point pattern: 1925 points
Average intensity 2.417323e-06 points per square unit
*Pattern contains duplicated points*
Coordinates are given to 3 decimal places
i.e. rounded to the nearest multiple of 0.001 units
Window: rectangle = [11810.03, 45404.24] x [25596.33, 49300.88] units
(33590 x 23700 units)
Window area = 796335000 square units
Key Point: Pay attention to the warning message regarding duplicates. In spatial point patterns analysis, a notable concern is the existence of duplicates. The statistical methods applied to spatial point patterns are predominantly built on the assumption that processes are straightforward, meaning that points cannot overlap.
3.4 Handling duplicated points
In order to check dupication in a ppp object:
any(duplicated(childcare_ppp))
[1] TRUE
multiplicity() function is used to count the number of co-indicence point.
DIY: Using the method you learned in previous section, check if any dusplicated point in this geospatial data.
any(duplicated(childcare_ppp_jit))
[1] FALSE
3.5 Creating owin object
When analysing spatial point patterns, it is a good practice to confine the analysis with a geographical area like Singapore boundary. In spatstat, an object called owin is specially designed to represent this polygonal region.
How to covert sg SpatialPolygon object into owin object of spatstat.
sg_owin <-as(sg_sp, "owin")
The output object can be displayed by using plot() function
The smoothing kernel used is gaussian, which is the default. Other smoothing methods are: “epanechnikov”, “quartic” or “disc”.
The intensity estimate is corrected for edge effect bias by using method described by Jones (1993) and Diggle (2010, equation 18.9). The default is FALSE.
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
The plot() function of Base R is then used to display the kernel density derived.
plot(kde_childcareSG_bw)
The density values of the output range from 0 to 0.000035 which is way too small to comprehend. This is because the default unit of measurement of svy21 is in meter. As a result, the density values computed is in “number of points per square meter”.
Before we move on to next section, it is good to know that you can retrieve the bandwidth used to compute the kde layer:
bw <-bw.diggle(childcareSG_ppp)bw
sigma
306.6986
4.1.2 Rescalling KDE values
rescale() is used to covert the unit of measurement from meter to kilometer:
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
plot(kde_childcareSG.bw)
Now we notice the output image looks identical to the earlier version, the only changes in the data values (refer to the legend).
4.2 Working with different automatic badwidth methods
Beside bw.diggle(), there are three other spatstat functions can be used to determine the bandwidth, they are: bw.CvL(), bw.scott(), and bw.ppl().
Let us take a look at the bandwidth return by these automatic bandwidth calculation methods by using:
bw.CvL(childcareSG_ppp.km)
sigma
4.543278
bw.scott(childcareSG_ppp.km)
sigma.x sigma.y
2.159749 1.396455
bw.ppl(childcareSG_ppp.km)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
sigma
0.3897114
bw.diggle(childcareSG_ppp.km)
sigma
0.3066986
Baddeley et. (2016) suggested the use of the bw.ppl() algorithm because in ther experience it tends to produce the more appropriate values when the pattern consists predominantly of tight clusters. But they also insist that if the purpose of once study is to detect a single tight cluster in the midst of random noise then the bw.diggle() method seems to work best.
This will be used to compare the output of using bw.diggle and bw.ppl methods.
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
par(mfrow=c(1,2))plot(kde_childcareSG.bw, main ="bw.diggle")plot(kde_childcareSG.ppl, main ="bw.ppl")
4.3 Working with different kernel methods
By default, the kernel method used in density.ppp() is gaussian. But there are three other options, namely: Epanechnikov, Quartic and Dics. Let’s take a look at what they’re like:
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
Bandwidth selection will be based on Gaussian kernel
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
Bandwidth selection will be based on Gaussian kernel
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
Bandwidth selection will be based on Gaussian kernel
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
Warning in density.ppp(childcareSG_ppp.km, sigma = bw.ppl, edge = TRUE, :
point-in-polygon test had difficulty with 215 points (total score not 0 or 1)
4.4 Fixed and Adaptive KDE
4.4.1 Computing KDE by using fixed bandwidth
Next, we will compute a KDE layer by defining a bandwidth of 600 meter. Notice that in the code chunk below, the sigma value used is 0.6. This is because the unit of measurement of childcareSG_ppp.km object is in kilometer, hence the 600m is 0.6km.
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
plot(kde_childcareSG_600)
4.4.2 Computing KDE by using adaptive bandwidth
Fixed bandwidth method is very sensitive to highly skew distribution of spatial point patterns over geographical units for example urban versus rural. One way to overcome this problem is by using adaptive bandwidth instead.
In this section, we will learn how to derive adaptive kernel density estimation by using density.adaptive() of spatstat.
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
Warning: point-in-polygon test had difficulty with 215 points (total score not
0 or 1)
plot(kde_childcareSG_adaptive)
We can compare the fixed and adaptive kernel density estimation outputs by using:
par(mfrow=c(1,2))plot(kde_childcareSG.bw, main ="Fixed bandwidth")plot(kde_childcareSG_adaptive, main ="Adaptive bandwidth")
4.4.3 Converting KDE output into grid object
The result is the same, we just convert it so that it is suitable for mapping purposes
Clark-Evans test
No edge correction
Z-test
data: childcareSG_ppp
R = 0.5062, p-value < 2.2e-16
alternative hypothesis: clustered (R < 1)
4.5.2 Clark and Evans Test: Choa Chu Kang planning area
In the code chunk below, clarkevans.test() of spatstat is used to performs Clark-Evans test of aggregation for childcare centre in Choa Chu Kang planning area.